﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EITSurferInfinityLib;


namespace ControlerLib
{
    /// <summary>
    /// Interaction logic for ColorScaleViewer.xaml
    /// </summary>
    public partial class ColorScaleViewer : UserControl
    {
        int[,] cmap;
        public ColorScaleViewer()
        {
            InitializeComponent();
        }

        public void CompleteColorScale()
        {
            int Size = 64;
            double RectHeight = (int)(DrawPlane.ActualHeight / Size);
            double RectWidth = (int)DrawPlane.ActualWidth;

            int width=1;
            int height=Size;

             WriteableBitmap bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
                
            int red;
            int green;
            int blue;
            int alpha;

            uint[] pixels = new uint[width * height];

            for (int i = 0; i < Size; i++)
            {
                alpha = cmap[i, 0];
                red = cmap[i,1];
                green = cmap[i, 2];
                blue = cmap[i, 3]; 
                
                pixels[i] = (uint)((alpha << 24) + (red << 16) + (green << 8) + blue);
            }
            bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, width * 4, 0);
            DrawPlane.Source = bitmap;
            DrawPlane.Stretch = Stretch.Fill;
        }


        public void SetColorMap(string selMap)
        {
            TriDVisualizer.ColorMap map = new TriDVisualizer.ColorMap(64, 255);
            switch (selMap)
            {
                case "Jet":
                    cmap = map.Jet();
                    break;
                case "Hot":
                    cmap = map.Hot();
                    break;
                case "Gray":
                    cmap = map.Gray();
                    break;
                case "Cool":
                    cmap = map.Cool();
                    break;
                case "Summer":
                    cmap = map.Summer();
                    break;
                case "Autumn":
                    cmap = map.Autumn();
                    break;
                case "Spring":
                    cmap = map.Spring();
                    break;
                case "Winter":
                    cmap = map.Winter();
                    break;
                case "SwisstomBlue":
                    cmap = map.SwisstomBlue();
                    break;
            }
        }
        private void ColorScale_Loaded(object sender, RoutedEventArgs e)
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                //SetColorMap("Jet");
                SetColorMap("SwisstomBlue");
                CompleteColorScale();
            }
        }
    }
}
